package com.etoak.stock.controller;

import com.etoak.stock.pojo.domin.MenuPermissionsDomain;
import com.etoak.stock.pojo.domin.SysUserRoleDomain;
import com.etoak.stock.service.UserRoleService;
import com.etoak.stock.vo.req.updatePermsByRoleIdReqVo;
import com.etoak.stock.vo.resp.PageResult;
import com.etoak.stock.vo.resp.R;
import io.swagger.annotations.Api;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author by 孙有泽
 * @Date 2024/10/26 14:39
 * @Description 权限相关接口处理器
 */
@Api("权限相关接口处理")
@RestController
@RequestMapping("/api")
public class UserRoleController {
    @Autowired
    private UserRoleService userRoleService;

    /*
     * @author 孙有泽
     * @date 2024/10/26 15:01
     * @description 分页查询当前角色信息
     */
    @GetMapping("/roles")
    public R<PageResult<SysUserRoleDomain>> getRoles(@RequestParam(value = "pageNum",required = true,defaultValue = "1")Integer pageNum,@RequestParam(value = "pageSize",required = true,defaultValue = "10")Integer pageSize){
        return userRoleService.getRoles(pageNum,pageSize);
    }
    /*
     * @author 孙有泽
     * @date 2024/10/26 15:05
     * @description 树状结构回显权限集合,底层通过递归获取权限数据集合
     */
    @GetMapping("/permissions/tree/all")
    public R<List<MenuPermissionsDomain>> getTree() {
        return userRoleService.getTree();
    }



    /*
     * @author 孙有泽
     * @date 2024/11/13 13:28
     * @description  更新用户的状态信息
     */

    @PostMapping("/role/{roleId}/{status}")
    public R updateStatus(@PathVariable("roleId")Long roleId,@PathVariable("status")Integer status){
        return  userRoleService.updateStatus(roleId,status);
    }

    /*
     * @author 孙有泽
     * @date 2024/11/13 13:37
     * @description 根据角色id删除角色信息
     */
    @DeleteMapping("/role/{roleId}")
    public R deleteRole(@PathVariable("roleId")Long roleId) {
        return userRoleService.deleteRole(roleId);
    }

    /*
     * @author 孙有泽
     * @date 2024/11/14 13:51
     * @description 添加角色和角色关联权限
     */
    @PutMapping("/role")
    public R updatePermsByRoles(@RequestBody updatePermsByRoleIdReqVo updatePermsByRoleIdReqVo){
        return userRoleService.updatePermsByRoles(updatePermsByRoleIdReqVo);

    }


}
